package org.example.springboot.controller;

import org.example.springboot.common.Result;
import org.example.springboot.entity.AgricultureKnowledge;
import org.example.springboot.service.AgricultureKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/agriculture-knowledge")
public class AgricultureKnowledgeController {
    @Autowired
    private AgricultureKnowledgeService agricultureKnowledgeService;

    @GetMapping
    public List<AgricultureKnowledge> list() {
        return agricultureKnowledgeService.findAll();
    }

    @GetMapping("/{id}")
    public AgricultureKnowledge getById(@PathVariable Long id) {
        return agricultureKnowledgeService.findById(id);
    }

    @PostMapping
    public AgricultureKnowledge add(@RequestBody AgricultureKnowledge knowledge) {
        return agricultureKnowledgeService.save(knowledge);
    }

    @PutMapping
    public AgricultureKnowledge update(@RequestBody AgricultureKnowledge knowledge) {
        return agricultureKnowledgeService.save(knowledge);
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        agricultureKnowledgeService.deleteById(id);
        return Result.success();
    }
} 